﻿Imports System.Xml.Serialization

Namespace Commands
    Public Class NewAvailablePartsNotification
        Inherits Framework.Net.CommandBase

        Private Const mRequestCode As String = "NewAvailablePartsNotification"
        Private Const mReplyCode As String = ""

        Public Sub New()
            MyBase.New(mRequestCode, mReplyCode)
        End Sub

        Public Class Request
            Public FileSHA512 As String
            Public Size As Long
            Public PartId As Integer
        End Class

        Friend Shared Sub SendNotificaction(ByVal node As Framework.Net.Node, ByVal file As Entities.Downloads.File, ByVal partId As Integer)
            Dim clsRequest As New Request
            clsRequest.FileSHA512 = file.SHA512Hash
            clsRequest.Size = file.Size
            clsRequest.PartId = partId
            Dim iMessageId As Integer = Framework.Net.Manager.GetNextMessageId
            node.SendCommandMessageAsync(iMessageId, mRequestCode, Framework.Serialization.ToXmlBytes(clsRequest))
        End Sub

        Public Overrides Sub HandleReply(ByVal envelope As Framework.Net.MessageEnvelope)
            Throw New NotImplementedException
        End Sub

        Public Overrides Sub HandleRequest(ByVal envelope As Framework.Net.MessageEnvelope)
            Dim clsRequest As Request = Framework.Serialization.FromXmlBytes(Of Request)(envelope.Message.Message)
            TransferEngine.DownloadQueue.AddNewAvailablePart(envelope.Node, clsRequest.FileSHA512, clsRequest.Size, clsRequest.PartId)
        End Sub
    End Class



End Namespace


